// DriveNotes. Copyright (c) 2011, Andrei Senchuk. All rights reserved.
package net.taviscaron.drivenotes.web.converter;

import java.util.Map;
import net.taviscaron.drivenotes.shared.model.entity.Place;
import static net.taviscaron.drivenotes.web.util.ParamUtils.parseLongParam;
import static net.taviscaron.drivenotes.web.util.ParamUtils.parseDoubleParam;
import static net.taviscaron.drivenotes.web.util.ParamUtils.parseStringParam;

/**
 * Place converter
 * @author Andrei Senchuk
 */
public class PlaceConverter extends FormConverter<Place> {
    @Override
    public Place convert(Map params, String prefix) throws InvalidFormException {
        try {
            Place place = new Place();
            place.setId(parseLongParam(params, "id", prefix));
            place.setDescription(parseStringParam(params, "description", prefix));
            place.setName(parseStringParam(params, "name", prefix));
            place.setLat(parseDoubleParam(params, "lat", prefix));
            place.setLon(parseDoubleParam(params, "lon", prefix));
            return place;
        } catch (IllegalArgumentException e) {
            throw new InvalidFormException();
        }
    }
}
